package com.jokerku.lottery.infrastructure.common;

import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Assert;

import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author: guzq
 * @CreateTime: 2022/08/31 10:36
 * @Description: 事件枚举
 * @Version: 1.0
 */
public enum EventEnum {

    /**
     * 订阅事件
     */
    SUBSCRIBE("subscribe"),
    /**
     * 取消订阅事件
     */
    UNSUBSCRIBE("unsubscribe"),
    /**
     * 抽奖事件
     */
    LOTTERY("lottery"),

    ;

    private String desc;

    EventEnum(String desc) {
        this.desc = desc;
    }


    private static final Map<String, EventEnum> ENUM_MAP;

    static {
        ENUM_MAP = new ConcurrentHashMap<>();
        ENUM_MAP.put(SUBSCRIBE.desc, SUBSCRIBE);
        ENUM_MAP.put(UNSUBSCRIBE.desc, UNSUBSCRIBE);
        ENUM_MAP.put(LOTTERY.desc, LOTTERY);
    }

    public static EventEnum getByStr(String str) {
        Assert.isTrue(StringUtils.isNotBlank(str), "EventEnumStr cannot be null");

        return ENUM_MAP.get(str);
    }
}
